<script>
import { post_md5 } from './common/request';
export default {
	onLaunch() {
		// #ifdef APP-PLUS
		uni.removeStorageSync('updata');
		const _handleClick = function(message) {
			var payload = message.payload;
			if (payload) {
				// payload 按照规范是 Object，但实际推送过来有可能是 String，需要多一步处理；
				if (typeof payload === 'string') {
					payload = JSON.parse(payload || '{}');
				}
				if (typeof payload === 'object') {
					if (payload.page) {
						setTimeout(function(res) {
							uni.navigateTo({
								url: payload.page + '?id=' + payload.id
							});
						}, 1000);
					}
				}
			}
		};

		const _handleReceive = function(message) {
			//根据payload传递过来的数据，打开一个详情
			var payload = message.payload;
			if (payload) {
				//如透传消息不符合格式，则“payload”属性为string类型
				//这里的示例以json字符串去解析，实际上也可以做字符串匹配
				if (typeof message.type == 'receive') {
					try {
						payload = JSON.parse(message.payload || '{}');
					} catch (error) {}
				} else if (typeof message.payload == 'receive') {
					//iOS应用正处于前台运行时收到推送，也触发receive事件，此时payload为json对象
					plus.push.createMessage(message.title, message.content);
				}
			}
		};
		plus.push.addEventListener('click', _handleClick);
		plus.push.addEventListener('receive', _handleReceive);
		// #endif
		let token = uni.getStorageSync('token');
		var that = this;
		if (token) {
			post_md5('/auth/chktoken')
				.then(res => {
					if (res.status === 404) {
						uni.removeStorageSync('token');
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
					if (res.data !== -1) {
						uni.switchTab({
							url: '/pages/main/main'
						});
					} else {
						uni.removeStorageSync('token');
						uni.reLaunch({
							url: '/pages/login/login'
						});
					}
				})
				.catch(err => {
					uni.removeStorageSync('token');
					uni.reLaunch({
						url: '/pages/login/login'
					});
				});
		}
	}
};
</script>

<style>
@import './static/iconfont/iconfont.css';

/*每个页面公共css */
/* uni-app默认全局使用flex布局。因为flex布局有利于跨更多平台，尤其是采用原生渲染的平台。如不了解flex布局，请参考http://www.w3.org/TR/css3-flexbox/。如不使用flex布局，请删除或注释掉本行。*/
body,
page {
	min-height: 100%;
	display: flex;
	font-size: 30upx;
}

/* #ifdef MP-BAIDU */
page {
	width: 100%;
	height: 100%;
	display: block;
}

swan-template {
	width: 100%;
	min-height: 100%;
	display: flex;
}

/* 原生组件模式下需要注意组件外部样式 */
custom-component {
	width: 100%;
	min-height: 100%;
	display: flex;
}

/* #endif */

/* 原生组件模式下需要注意组件外部样式 */
m-input {
	width: 100%;
	min-height: 100%;
	display: flex;
	font-size: 30upx;
	flex: 1;
}

.jump-btn {
	margin-top: 80upx;
	width: 118upx;
	height: 50upx;
	border: 2upx solid #02a8f4;
	border-radius: 24px;
	font-size: 28upx;
	font-weight: bold;
	color: #02a8f4;
	text-align: center;
	line-height: 50upx;
	position: fixed;
	right: 34upx;
	/* top: var(--window-top); */
	z-index: 10;
}

.container-white {
	display: flex;
	flex: 1;
	flex-direction: column;
	background: #ffffff;
}

.container-gray {
	display: flex;
	flex: 1;
	flex-direction: column;
	background: #ededed;
	width: 100%;
}

.content {
	display: flex;
	flex: 1;
	flex-direction: column;
	background-color: #efeff4;
	padding: 20upx;
}

.flex-box {
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.flex-column {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.head {
	background: #ffffff;
	font-size: 30upx;
	font-weight: 400;
	color: #333333;
	padding: 36upx 40upx;
	margin: 1px 0;
	border-bottom: 1px solid #ededed;
}

.input-group {
	margin-top: 40upx;
}

.input-group::before {
	position: absolute;
	right: 0;
	top: 0;
	left: 0;
	height: 1upx;
	content: '';
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	background-color: #c8c7cc;
}

.input-group::after {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 0;
	height: 1upx;
	content: '';
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	background-color: #c8c7cc;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
}

.input-row .title {
	/* height: 50upx;
		min-height: 50upx; */
	padding: 15upx 0;
	padding-left: 30upx;
	/* line-height: 50upx; */
	white-space: nowrap;
}

.input-row.border::after {
	position: absolute;
	right: 0;
	bottom: 0;
	left: 15upx;
	height: 1upx;
	content: '';
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	background-color: #c8c7cc;
}

.prompt {
	color: #dc143c;
	font-size: 20upx;
	margin-top: 10upx;
}

.btn-row {
	margin-top: 50upx;
	padding: 20upx;
}

button.primary {
	background-color: #02a8f4;
	display: flex;
	align-items: center;
	justify-content: center;
}

.cancel {
	border: 1px solid #02a8f4;
	background: #ffffff;
	color: #02a8f4;
	display: flex;
	align-items: center;
	justify-content: center;
}

button:after {
	border: none !important;
	/* background: #02A8F4; */
}

.footer-btn {
	color: #ffffff;
	flex: 1;
	border: none !important;
	border-radius: 0 !important;
}

.footer {
	position: fixed;
	bottom: 0;
	width: 100%;
	display: flex;
	align-items: center;
}

/* 选项 */
.options {
	display: flex;
	margin: 20upx 0;
}

.stide {
	width: 60upx;
	height: 60upx;
	border: 1px solid #02a8f4;
	border-radius: 50%;
	color: #02a8f4;
	font-size: 28upx;
	margin-right: 20upx;
	display: flex;
	align-items: center;
	justify-content: center;
}

.isCheck {
	background: #ffffff;
	color: #02a8f4;
}

.cut-off {
	width: 4upx;
	height: 60upx;
	background: #ffffff;
}

.model-footer {
	display: flex;
	font-size: 28upx;
}

.model-content {
	color: #333333;
	text-align: center;
	margin-top: 46upx;
	margin-bottom: 86upx;
}

.model-footer-btn {
	width: 200upx;
	height: 80upx;
	border-radius: 40upx;
	font-size: 28upx;
	margin: auto;
}

/* 一级分类切换 */
.cate-box {
	width: 750upx;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 20upx;
}

.cate-title {
	width: 160upx;
	height: 60upx;
	line-height: 60upx;
	background: #ffffff;
	color: #02a8f4;
	border: 1px solid #02a8f4;
	text-align: center;
	font-size: 26upx;
}

.cate-active {
	background: #02a8f4;
	color: #ffffff;
}

/* 二级分类切换 */
.head-tab {
	width: 100%;
	white-space: nowrap;
	position: fixed;
	background: #ffffff;
	z-index: 999;
	top: var(--window-top);
	left: 0;
}

.tab-bar-item {
	font-size: 28upx;
	color: #32343d;
	min-width: 250upx;
}

.tab-bar-title {
	text-align: center;
	width: 100%;
	height: 88upx;
	line-height: 88upx;
}

.underline {
	width: 36%;
	height: 8upx;
	/* background:#FFFFFF; */
	background: #02a8f4;
	border-radius: 4px;
	margin: auto;
}

.sub-cate-active {
	/* background:#02A8F4; */
	color: #02a8f4;
}
</style>
